<template>
  <div class="box">
    <div class="container right-panel-active">
      <div class="container_form container--signin">
        <el-form
            :model="ruleForm"
            :rules="rules"
            ref="ruleForm"
            label-width="100px"
            class="form"
        >
          <h2 class="form_title">登录</h2>

          <el-form-item prop="username">
            <el-input v-model="ruleForm.username" placeholder="ID"></el-input>
          </el-form-item>

          <el-form-item prop="password">
            <el-input
                v-model="ruleForm.password"
                type="password"
                placeholder="密码"
            ></el-input>
          </el-form-item>

          <el-form-item>
            <el-button type="primary" @click="submitForm('ruleForm')"
            >立即登录
            </el-button
            >
            <el-button
                icon="el-icon-delete"
                @click="resetForm('ruleForm')"
                circle
            ></el-button>
          </el-form-item>
        </el-form>
      </div>

      <!-- 背景 -->
      <div class="slidershow">
        <div
            class="slidershow--image"
            style="
            background-image: url('https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fpic1.win4000.com%2Fwallpaper%2F2017-10-30%2F59f689d50f432.jpg%3Fdown&refer=http%3A%2F%2Fpic1.win4000.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1642066325&t=09747a5a7d0e935d92a92aff9e0ff2ba');
          "
        ></div>
      </div>
    </div>
  </div>
</template>

<script>
const errMsg = "请检查你的用户名密码";
export default {
  name: "Login",
  data() {
    return {
      ruleForm: {
        username: "",
        password: "",
      },
      rules: {
        username: [
          {required: true, message: "请输入用户名", trigger: "blur"},
          {
            min: 4,
            max: 4,
            message: " ",
            trigger: "blur",
          },
        ],
        password: [
          {required: true, message: "请输入密码", trigger: "change"},
          {
            min: 6,
            max: 17,
            message: "长度异常，请检查密码是否正确",
            trigger: "blur",
          },
        ],
      },
    };
  },
  methods: {
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          var form = this.ruleForm;
          const _this = this;
          this.$axios
              .post(
                  "/denglu?username=" + form.username + "&password=" + form.password
              )
              .then((res) => {
                console.log(res);
                var userInfo = res.data;
                //保存数据
                _this.$store.commit("SET_USERINFO", userInfo);
                // console.log(_this.$store.getters.getUserInfo);//取出数据
                //页面跳转
                _this.$router.push("/home");
              });
        } else {
          const h = this.$createElement;
          this.$notify.error({
            title: "错误",
            message: h("i", {style: "color: teal"}, errMsg),
          });
          return false;
        }
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
  },
};
</script>

<style scoped>
.container {
  background-color: var(--white);
  border-radius: var(--button-radius);
  box-shadow: 0 0.9rem 1.7rem rgba(0, 0, 0, 0.25),
  0 0.7rem 0.7rem rgba(0, 0, 0, 0.22);
  height: var(--max-height);
  max-width: var(--max-width);
  overflow: hidden;
  position: relative;
  width: 60%;
  background-color: blue;

  height: 60%;
  place-items: center;

  border-radius: 0.7rem;
}

:root {
  /* 颜色 */
  --white: #e9e9e9;
  --gray: #333;
  --blue-r: #315a7491;

  /* 圆角 */
  --button-radius: 0.7rem;

  /* 大小 */
  --max-width: 758px;
  --max-height: 420px;

  font-size: 16px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen,
  Ubuntu, Cantarell, "Open Sans", "Helvetica Neue", sans-serif;
}

.box {
  align-items: center;
  background-color: var(--white);
  /* background-color: red; */

  background-attachment: fixed;
  background-position: center;
  background-repeat: no-repeat;
  background-size: cover;
  display: grid;
  height: 100vh;
  place-items: center;
}

.form_title {
  font-weight: 300;
  margin: 0;
  margin-bottom: 1.25rem;
}

.link {
  color: var(--gray);
  font-size: 0.9rem;
  margin-top: 1.5rem;
  text-decoration: none;
}

.container_form {
  height: 100%;
  position: absolute;
  top: 0;
  transition: all 0.6s ease-in-out;
}

.container--signin {
  left: 0;
  width: 50%;
  z-index: 5;
}

.btn {
  background-color: var(--blue);
  background-image: linear-gradient(
      90deg,
      var(--blue) 0%,
      var(--lightblue) 74%
  );
  border-radius: 20px;
  border: 0.2px solid var(--blue-r);
  color: var(--white);
  cursor: pointer;
  font-size: 0.8rem;
  font-weight: bold;
  letter-spacing: 0.1rem;
  padding: 0.9rem 4rem;
  text-transform: uppercase;
  transition: transform 80ms ease-in;
}

.form > .btn {
  margin-top: 1.5rem;
}

.btn:active {
  transform: scale(0.95);
}

.btn:focus {
  outline: none;
}

.form {
  /* background-color: var(--white); */
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  padding: 0 3rem;
  height: 100%;
  text-align: center;
}

.input {
  background-color: #fff;
  border: none;
  border-radius: 50px;
  padding: 0.9rem 0.9rem;
  margin: 0.5rem 0;
  width: 100%;
}

.slidershow {
  position: absolute;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
}

.slidershow--image {
  position: absolute;
  width: 100%;
  height: 100%;
  background: no-repeat 50% 50%;
  background-size: cover;
  transform: scale(1.2);
}
</style>